************************************************
***Title: robustness_weather_lags.do
***Creators: Joelle Abramowitz, Shooshan Danagoulian, and Owen Fleming*
***Notes: This file produces the estimates of the effect of pollen exposure on suicide using lags of weather as a control. 

*For questions, contact
*Owen Fleming
*hg3490@wayne.edu
************************************************


**********SETUP
use data/for_analysis, clear

foreach i in $weather {
bysort county (date): gen `i'_1 = `i'[_n-1]
}

global weather_with_lags tmin tmin_1 tmin_sq tmin_sq_1 tmax tmax_1 tmax_sq tmax_sq_1 tmean tmean_1 tmean_sq tmean_sq_1 any_precip any_precip_1 wind_speed wind_speed_1 wind_speed_sq wind_speed_sq_1


**********PRODUCE ESTIMATES
*generate sample
ppmlhdfe count pollen_q2_ls pollen_q3_ls pollen_q4_ls $weather_with_lags, absorb(county year_month month_day) cluster(county) tolerance(1e-06)
gen sample = e(sample)

*Treatment: location-season quartiles
eststo main_s1_lagweather: poisson count pollen_q2_ls pollen_q3_ls pollen_q4_ls $weather_with_lags if sample==1, cluster(county) tolerance(1e-06)
estadd ysumm
estadd scalar counties = e(N_clust)
estadd local Controls "Weather, Lagged Weather" 
estadd local FE ""

*Treatment: location-season quartiles
eststo main_s2_lagweather: ppmlhdfe count pollen_q2_ls pollen_q3_ls pollen_q4_ls $weather_with_lags if sample==1, absorb(county month year) cluster(county) tolerance(1e-06)
estadd ysumm
estadd scalar counties = e(N_clust)
estadd local Controls "Weather, Lagged Weather" 
estadd local FE "County, Month, Year"

*Treatment: location-season quartiles
eststo main_s3_lagweather: ppmlhdfe count pollen_q2_ls pollen_q3_ls pollen_q4_ls $weather_with_lags if sample==1, absorb(county year_month month_day) cluster(county) tolerance(1e-06)
estadd ysumm
estadd scalar counties = e(N_clust)
estadd local Controls "Weather, Lagged Weather" 
estadd local FE "County, Year x Month, Month x Day"

drop sample


**********EXPORT
estout using results/robustness_weather_lags.xls, cells(b(star label(Coef.) fmt(4)) se(par(`"="("'`")""') label(Std. Err.) fmt(4))) stats(ymean N counties Controls FE) starlevels(* 0.1 ** 0.05 *** 0.01) keep(pollen_q2_ls pollen_q3_ls pollen_q4_ls) legend label replace 
eststo clear


